package Stragos.servlet.Reserva;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.Session;

import Stragos.excepcion.DAOExcepcion;
import Stragos.modelo.Usuario;
import Stragos.negocio.GestionCliente;
import Stragos.negocio.GestionReserva;
import Stragos.negocio.GestionSalas;

/**
 * Servlet implementation class generarReserva
 */
@WebServlet("/generarReserva")
public class generarReserva extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public generarReserva() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int idlocal=0; 
			
		String accion=request.getParameter("txtValor");
				
		GestionReserva objre=new GestionReserva();
		GestionSalas objSala=new GestionSalas();
		
		try {
			if (accion.equals("0")){
				idlocal=Integer.parseInt(request.getParameter("selLocal"));
				request.setAttribute("listSalas", objSala.obtener(idlocal));
			}
						
			request.setAttribute("cbLocalText",request.getParameter("combotexto"));
			
			HttpSession session = request.getSession();
			Usuario usuario_actual = (Usuario)session.getAttribute("USUARIO_ACTUAL");
			GestionCliente objcli=new GestionCliente();
			
			if (accion.equals("1")) {
				
				String fecha=request.getParameter("fec_nac");
				String correo=objcli.buscarCliente(usuario_actual.getDni()).get(0).getCorreo();
				String clave=usuario_actual.getClave();
				int salaid=Integer.parseInt(request.getParameter("selSala"));
				String descripcion=request.getParameter("txtdesc");
				
				objre.crearReserva(fecha, correo, clave, salaid, descripcion);
				}
		    if (accion.equals("2")){
				int id=Integer.parseInt(request.getParameter("chkSala"));
								
				}
		    if(accion.equals("3")){
				int idreserva=Integer.parseInt(request.getParameter("txtelim"));
				objre.eliminar(idreserva);
				}
			
			RequestDispatcher rd = request.getRequestDispatcher("reservaSala.jsp");
			rd.forward(request, response);
			
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
